Imports MigraDoc.DocumentObjectModel
Imports MigraDoc.Rendering
Imports System.IO

Public Class frm<OwnerU>_<TableU>
    Inherits System.Web.UI.Page

    Private cls<Database>Data As New sr<Database>Data.<Database>DataServiceClient
    Private cls<OwnerU>_<TableU>Data As New sr<OwnerU>_<TableU>.I<OwnerU>_<TableU>ServiceClient
    <If Loop>
          <IsFKey>
    Private cls<OwnerU>_<TableU>ComboData As New sr<OwnerU>_<TableU>Combo.I<OwnerU>_<TableU>ComboServiceClient
	    <ExitLoop>
        </If Loop>
    Private dv<OwnerU>_<TableU> As DataView

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
    <If Loop>
      <IsFKey>
            Session("<FieldU>_SelectedValue") = ""
    </If Loop>

            Session.Remove("dv<OwnerU>_<TableU>")
            Session.Remove("Row")

    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
            cmbFields.Items.Add("<FieldC>")
    </If Loop>

            cmbCondition.Items.Add("Contains")
            cmbCondition.Items.Add("Equals")
            cmbCondition.Items.Add("Starts with...")
            cmbCondition.Items.Add("More than...")
            cmbCondition.Items.Add("Less than...")
            cmbCondition.Items.Add("Equal or more than...")
            cmbCondition.Items.Add("Equal or less than...")

            cmbRecords.Items.Add("5")
            cmbRecords.Items.Add("10")
            cmbRecords.Items.Add("25")
            cmbRecords.Items.Add("50")
            cmbRecords.Items.Add("100")
            cmbRecords.Items.Add("500")

            LoadGrid<OwnerU>_<TableU>()
        End If
    End Sub

    <If Loop>
      <IsFKey>
    Private Sub Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>(ByVal e As GridViewRowEventArgs)
        Dim <OwnerU>_<TableU>_<ROwnerU>_<RTableU>List As List(Of sr<OwnerU>_<TableU>Combo.<OwnerU>_<TableU>_<ROwnerU>_<RTableU>Class<MiscTag>)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim txt<FieldU> As DropDownList = DirectCast(e.Row.FindControl("txt<FieldU>"), DropDownList)
            If txt<FieldU> IsNot Nothing Then
                Try
                    <OwnerU>_<TableU>_<ROwnerU>_<RTableU>List = cls<OwnerU>_<TableU>ComboData.List<OwnerU>_<TableU>_<ROwnerU>_<RTableU><MiscTag>
            <IsFKey>
                    txt<FieldU>.DataSource = <OwnerU>_<TableU>_<ROwnerU>_<RTableU>List
                    txt<FieldU>.DataValueField = "<RFieldU>"
                    txt<FieldU>.DataTextField = "<RDisplayFieldU>"
                    txt<FieldU>.DataBind()
                    txt<FieldU>.SelectedValue = CStr(Session("<FieldU>_SelectedValue"))
                Catch
                End Try
            End If
        End If
        If e.Row.RowType = DataControlRowType.Footer Then
            Dim txtNew<FieldU> As DropDownList = DirectCast(e.Row.FindControl("txtNew<FieldU>"), DropDownList)
            If txtNew<FieldU> IsNot Nothing Then
                Try
                    <OwnerU>_<TableU>_<ROwnerU>_<RTableU>List = cls<OwnerU>_<TableU>ComboData.List<OwnerU>_<TableU>_<ROwnerU>_<RTableU><MiscTag>
            <IsFKey>
                    txtNew<FieldU>.DataSource = <OwnerU>_<TableU>_<ROwnerU>_<RTableU>List
                    txtNew<FieldU>.DataValueField = "<RFieldU>"
                    txtNew<FieldU>.DataTextField = "<RDisplayFieldU>"
                    txtNew<FieldU>.DataBind()
                Catch
                End Try
            End If
        End If
    End Sub

    </If Loop>
    Private Sub LoadGrid<OwnerU>_<TableU>()
        Try
            If Not IsNothing(Session("dv<OwnerU>_<TableU>")) Then
                dv<OwnerU>_<TableU> = CType(Session("dv<OwnerU>_<TableU>"), DataView)
            Else ' DataView was not found in the Session.
            	dv<OwnerU>_<TableU> = cls<OwnerU>_<TableU>Data.SelectAll().Tables(0).DefaultView
            	Session("dv<OwnerU>_<TableU>") = dv<OwnerU>_<TableU>
            End If
            If dv<OwnerU>_<TableU>.Count > 0 Then
                With grd<TableU>
                    .DataSource = dv<OwnerU>_<TableU>
                    .DataBind()
                End With
            End If
            If dv<OwnerU>_<TableU>.Count = 0 Then
                Dim dt As New DataTable()
                dt.Rows.Add(dt.NewRow())
            <If Loop>
                <IsComboBox (Db)>
                dt.Columns.Add("<RDisplayFieldU>", Type.GetType("System.<VBType>"))
                <IsNotComboBox (Db)>
                dt.Columns.Add("<FieldU>", Type.GetType("System.<VBType>"))
            </If Loop>
                dv<OwnerU>_<TableU> = dt.DefaultView
                Session("dv<OwnerU>_<TableU>") = dv<OwnerU>_<TableU>

                With grd<TableU>
                    .DataSource = dv<OwnerU>_<TableU>
                    .DataBind()
                End With

                Dim TotalColumns As Integer = grd<TableU>.Rows(0).Cells.Count
                grd<TableU>.Rows(0).Cells.Clear()
                grd<TableU>.Rows(0).Cells.Add(New TableCell())
                grd<TableU>.Rows(0).Cells(0).ColumnSpan = TotalColumns
                grd<TableU>.Rows(0).Cells(0).Text = "No Record Found"
            End If
            dv<OwnerU>_<TableU>.Sort = htmlHiddenSortExpression.Value
        Catch ex As Exception
            ec.ShowMessage(ex.Message, " <Head> ")
        End Try
    End Sub

    Protected Sub grd<TableU>_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles grd<TableU>.RowDataBound
        <If Loop>
          <IsFKey>
        Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>(e)
        </If Loop>
        If e.Row.RowType = DataControlRowType.DataRow Then
        <If Loop>
           <IsIdentity>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsCheckBox>
            Dim txt<FieldU> As CheckBox = DirectCast(e.Row.FindControl("txt<FieldU>"), CheckBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsNumericUpDown>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsDateTimePicker>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsMaskedTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsMultilineTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsRichTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsComboBox>
            Dim txt<FieldU> As DropDownList = DirectCast(e.Row.FindControl("txt<FieldU>"), DropDownList)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsComboBox (Db)>
            Dim txt<FieldU> As DropDownList = DirectCast(e.Row.FindControl("txt<FieldU>"), DropDownList)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsCheckBox>
            Dim txt<FieldU> As CheckBox = DirectCast(e.Row.FindControl("txt<FieldU>"), CheckBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsNumericUpDown>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsDateTimePicker>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsMaskedTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsMultilineTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsRichTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(e.Row.FindControl("txt<FieldU>"), TextBox)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsComboBox>
            Dim txt<FieldU> As DropDownList = DirectCast(e.Row.FindControl("txt<FieldU>"), DropDownList)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsComboBox (Db)>
            Dim txt<FieldU> As DropDownList = DirectCast(e.Row.FindControl("txt<FieldU>"), DropDownList)
            If txt<FieldU> IsNot Nothing Then
                txt<FieldU>.Enabled = False
            End If
        </If Loop>
        End If
        <If Loop>
           <IsIdentity>
        If e.Row.RowType = DataControlRowType.Footer Then
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsIdentity>
            Dim txtNew<FieldU> As TextBox = DirectCast(e.Row.FindControl("txtNew<FieldU>"), TextBox)
            If txtNew<FieldU> IsNot Nothing Then
                txtNew<FieldU>.Enabled = False
            End If
        </If Loop>
        <If Loop>
           <IsIdentity>
            txtNew<FieldU>.Text = System.Convert.ToString(cls<Database>Data.getAutoID("New", "<Table>"))
        </If Loop>
        <If Loop>
           <IsIdentity>
        End If
           <ExitLoop>
        </If Loop>
    End Sub

    Protected Sub grd<TableU>_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles grd<TableU>.RowCancelingEdit
        grd<TableU>.EditIndex = -1
        LoadGrid<OwnerU>_<TableU>()
    End Sub

    Protected Sub grd<TableU>_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles grd<TableU>.RowEditing
        grd<TableU>.EditIndex = e.NewEditIndex
        Edit()
    End Sub

    Protected Sub grd<TableU>_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles grd<TableU>.RowUpdating
        Session("Row") = e.RowIndex
        UpdateRecord()
    End Sub

    Protected Sub grd<TableU>_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles grd<TableU>.RowDeleting
        Session("Row") = e.RowIndex
        DeleteRecord()
    End Sub

    Protected Sub grd<TableU>_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grd<TableU>.RowCommand
        If e.CommandName.Equals("Insert") Then
            InsertRecord()
        End If
    End Sub

    Protected Sub grd<TableU>_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles grd<TableU>.PreRender
        Dim gv As GridView = CType(sender, GridView)
        Dim gvr As GridViewRow = CType(gv.BottomPagerRow, GridViewRow)
        If gvr IsNot Nothing Then
            gvr.Visible = True
        End If
    End Sub

    Private Sub grd<TableU>_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grd<TableU>.PageIndexChanging
        grd<TableU>.PageIndex = e.NewPageIndex
        LoadGrid<OwnerU>_<TableU>()
    End Sub

    Private Sub grd<TableU>_Sorting(sender As Object, e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grd<TableU>.Sorting
        htmlHiddenSortExpression.Value = e.SortExpression & " " & GetSortDirection(e.SortExpression)
        LoadGrid<OwnerU>_<TableU>()
    End Sub

    Private Sub Edit()
        Try
            Dim cls<OwnerU>_<TableU> As New sr<OwnerU>_<TableU>.<OwnerU>_<TableU>Class
        <If Loop>
           <IsPKey>
            Dim lbl<FieldU> As Label = DirectCast(grd<TableU>.Rows(grd<TableU>.EditIndex).FindControl("lbl<FieldU>"), Label)
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text)
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
            Dim lbl<FieldU> As Label = DirectCast(grd<TableU>.Rows(grd<TableU>.EditIndex).FindControl("lbl<FieldU>"), Label)
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text)
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
            Dim lbl<FieldU> As Label = DirectCast(grd<TableU>.Rows(grd<TableU>.EditIndex).FindControl("lbl<FieldU>"), Label)
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text)
           <ExitLoop>
        </If Loop>
            cls<OwnerU>_<TableU> = cls<OwnerU>_<TableU>Data.Select_Record(cls<OwnerU>_<TableU>)

    <If Loop>
      <IsFKey>
            Session("<FieldU>_SelectedValue") = cls<OwnerU>_<TableU>.<FieldU>
    </If Loop> 

            LoadGrid<OwnerU>_<TableU>()
        Catch
        End Try
    End Sub

    Private Sub InsertRecord()
        Try
    <If Loop>
    	<IsNotIdentity>
    	<And>
    	<IsCheckBox>
            Dim txtNew<FieldU> As CheckBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), CheckBox)
    	<IsNotIdentity>
    	<And>
    	<IsNumericUpDown>
            Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsNotIdentity>
    	<And>
    	<IsDateTimePicker>
            Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsNotIdentity>
    	<And>
    	<IsTextBox>
            Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsNotIdentity>
    	<And>
    	<IsMaskedTextBox>
            Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsNotIdentity>
    	<And>
    	<IsMultilineTextBox>
            Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsNotIdentity>
    	<And>
    	<IsRichTextBox>
            Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsNotIdentity>
    	<And>
    	<IsComboBox>
            Dim txtNew<FieldU> As DropDownList = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), DropDownList)
    	<IsNotIdentity>
    	<And>
    	<IsComboBox (Db)>
            Dim txtNew<FieldU> As DropDownList = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), DropDownList)
    </If Loop>

            Dim cls<OwnerU>_<TableU> As New sr<OwnerU>_<TableU>.<OwnerU>_<TableU>Class
            If VerifyDataNew() = True Then
                With cls<OwnerU>_<TableU>
                <If Loop>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(txtNew<FieldU>.Checked, True, False)
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                          
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.SelectedValue), Nothing, CType(txtNew<FieldU>.SelectedValue, <VBType>?))
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(txtNew<FieldU>.Checked, True, False)
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, CType(txtNew<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.Text), Nothing, txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                          
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txtNew<FieldU>.SelectedValue), Nothing, txtNew<FieldU>.SelectedValue.ToString)
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(IIf(txtNew<FieldU>.Checked, True, False))
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                          
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue)
--------------------------------------------------------------------------------------------------------<Comment>
                </If Loop>
                End With
                Dim bSucess As Boolean
                bSucess = cls<OwnerU>_<TableU>Data.Add(cls<OwnerU>_<TableU>)
                If bSucess = True Then
                    Session.Remove("dv<OwnerU>_<TableU>")
                    LoadGrid<OwnerU>_<TableU>()
                Else
                    ec.ShowMessage(" Insert failed. ", " <Head> ")
                End If
            End If
        Catch
        End Try
    End Sub

    Private Sub UpdateRecord()
        Try
    <If Loop>
    	<IsCheckBox>
            Dim txt<FieldU> As CheckBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), CheckBox)
    	<IsNumericUpDown>
            Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsDateTimePicker>
            Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsMaskedTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsMultilineTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsRichTextBox>
            Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsComboBox>
            Dim txt<FieldU> As DropDownList = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), DropDownList)
    	<IsComboBox (Db)>
            Dim txt<FieldU> As DropDownList = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), DropDownList)
    </If Loop>

            Dim ocls<OwnerU>_<TableU> As New sr<OwnerU>_<TableU>.<OwnerU>_<TableU>Class
            Dim cls<OwnerU>_<TableU> As New sr<OwnerU>_<TableU>.<OwnerU>_<TableU>Class
        <If Loop>
           <IsPKey>
            ocls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text)
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
            ocls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text)
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
            ocls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text)
           <ExitLoop>
        </If Loop>
            ocls<OwnerU>_<TableU> = cls<OwnerU>_<TableU>Data.Select_Record(ocls<OwnerU>_<TableU>) 

            If VerifyData() = True Then
                With cls<OwnerU>_<TableU>
                <If Loop>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(txt<FieldU>.Checked, True, False)
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                          
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.SelectedValue), Nothing, CType(txt<FieldU>.SelectedValue, <VBType>?))
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(txt<FieldU>.Checked, True, False)
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, CType(txt<FieldU>.Text, <VBType>?))
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.Text), Nothing, txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                          
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    .<FieldU> = If(String.IsNullOrEmpty(txt<FieldU>.SelectedValue), Nothing, txt<FieldU>.SelectedValue.ToString)
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(IIf(txt<FieldU>.Checked, True, False))
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                          
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.Text)
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
                    .<FieldU> = <Convert>(txt<FieldU>.SelectedValue)
--------------------------------------------------------------------------------------------------------<Comment>
                </If Loop>
                End With
                Dim bSucess As Boolean
                bSucess = cls<OwnerU>_<TableU>Data.Update(ocls<OwnerU>_<TableU>, cls<OwnerU>_<TableU>)
                If bSucess = True Then
                    Session.Remove("dv<OwnerU>_<TableU>")
                    grd<TableU>.EditIndex = -1
                    LoadGrid<OwnerU>_<TableU>()
                Else
                    ec.ShowMessage(" Update failed. ", " <Head> ")
                End If
            End If
        Catch
        End Try
    End Sub

    Private Sub DeleteRecord()
        Try
            Dim cls<OwnerU>_<TableU> As New sr<OwnerU>_<TableU>.<OwnerU>_<TableU>Class
        <If Loop>
           <IsPKey>
            Dim lbl<FieldU> As Label = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("lbl<FieldU>"), Label)
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text)
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
            Dim lbl<FieldU> As Label = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("lbl<FieldU>"), Label)
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text)
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
            Dim lbl<FieldU> As Label = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("lbl<FieldU>"), Label)
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text)
           <ExitLoop>
        </If Loop>
            cls<OwnerU>_<TableU> = cls<OwnerU>_<TableU>Data.Select_Record(cls<OwnerU>_<TableU>) 
            Dim bSucess As Boolean
            bSucess = cls<OwnerU>_<TableU>Data.Delete(cls<OwnerU>_<TableU>)
            If bSucess = True Then
                Session.Remove("dv<OwnerU>_<TableU>")
                LoadGrid<OwnerU>_<TableU>()
            Else
                ec.ShowMessage(" Delete failed. ", " <Head> ")
            End If
        Catch
        End Try
    End Sub

    Private Function VerifyData() As Boolean
    <If Loop>
    	<IsCheckBox>
        Dim txt<FieldU> As CheckBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), CheckBox)
    	<IsNumericUpDown>
        Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsDateTimePicker>
        Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsTextBox>
        Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsMaskedTextBox>
        Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsMultilineTextBox>
        Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsRichTextBox>
        Dim txt<FieldU> As TextBox = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), TextBox)
    	<IsComboBox>
        Dim txt<FieldU> As DropDownList = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), DropDownList)
    	<IsComboBox (Db)>
        Dim txt<FieldU> As DropDownList = DirectCast(grd<TableU>.Rows(CInt(Session("Row"))).FindControl("txt<FieldU>"), DropDownList)
    </If Loop>

        <If Loop>
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsCheckBox>
          
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsNumericUpDown>
        If txt<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsDateTimePicker>
        
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsTextBox>
        If txt<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsMaskedTextBox>
        If txt<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsMultilineTextBox>
        If txt<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsRichTextBox>
        If txt<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsPictureBox>
        
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsComboBox>
        If txt<FieldU>.SelectedIndex = -1 Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsComboBox (Db)>
        If txt<FieldU>.SelectedIndex = -1 Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txt<FieldU>.Focus()
            Return False
        End If         
      </If Loop>
        Return True
    End Function

    Private Function VerifyDataNew() As Boolean
    <If Loop>
    	<IsCheckBox>
        Dim txtNew<FieldU> As CheckBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), CheckBox)
    	<IsNumericUpDown>
        Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsDateTimePicker>
        Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsTextBox>
        Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsMaskedTextBox>
        Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsMultilineTextBox>
        Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsRichTextBox>
        Dim txtNew<FieldU> As TextBox = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), TextBox)
    	<IsComboBox>
        Dim txtNew<FieldU> As DropDownList = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), DropDownList)
    	<IsComboBox (Db)>
        Dim txtNew<FieldU> As DropDownList = DirectCast(grd<TableU>.FooterRow.FindControl("txtNew<FieldU>"), DropDownList)
    </If Loop>

        <If Loop>
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsCheckBox>
          
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsNumericUpDown>
        If txtNew<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsDateTimePicker>
        
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsTextBox>
        If txtNew<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsMaskedTextBox>
        If txtNew<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsMultilineTextBox>
        If txtNew<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsRichTextBox>
        If txtNew<FieldU>.Text = "" Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsPictureBox>
        
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsComboBox>
        If txtNew<FieldU>.SelectedIndex = -1 Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If
           <IsNotIdentity>
           <And>
           <IsNotNull>
           <And>
           <IsComboBox (Db)>
        If txtNew<FieldU>.SelectedIndex = -1 Then
            ec.ShowMessage(" <FieldC> is Required ",  " <Head> ")
            txtNew<FieldU>.Focus()
            Return False
        End If         
      </If Loop>
---------------------------------------<Comment>
        <If Loop>
           <IsNotIdentityCount>
        If _
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsNumericUpDown>
            txtNew<FieldU>.Text <> "" _
	            <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsTextBox>
            txtNew<FieldU>.Text <> "" _
	            <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMaskedTextBox>
            txtNew<FieldU>.Text <> "" _
	            <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMultilineTextBox>
            txtNew<FieldU>.Text <> "" _
	            <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsRichTextBox>
            txtNew<FieldU>.Text <> "" _
	            <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsComboBox (Db)>
             txtNew<FieldU>.SelectedIndex <> -1 _
	            <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsNumericUpDown>
           <And>
           <IsCurRow<>[0]>
            And txtNew<FieldU>.Text <> "" _
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsTextBox>
           <And>
           <IsCurRow<>[0]>
            And txtNew<FieldU>.Text <> "" _
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMaskedTextBox>
           <And>
           <IsCurRow<>[0]>
            And txtNew<FieldU>.Text <> "" _
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMultilineTextBox>
           <And>
           <IsCurRow<>[0]>
            And txtNew<FieldU>.Text <> "" _
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsRichTextBox>
           <And>
           <IsCurRow<>[0]>
            And txtNew<FieldU>.Text <> "" _
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsComboBox (Db)>
           <And>
           <IsCurRow<>[0]>
             And txtNew<FieldU>.SelectedIndex <> -1 _
           <IsNotIdentity>
           <And>
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsNumericUpDown>
             txtNew<FieldU>.Text <> "" _
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsTextBox>
             txtNew<FieldU>.Text <> "" _
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMaskedTextBox>
             txtNew<FieldU>.Text <> "" _
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMultilineTextBox>
             txtNew<FieldU>.Text <> "" _
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsRichTextBox>
             txtNew<FieldU>.Text <> "" _
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsComboBox (Db)>
             txtNew<FieldU>.SelectedIndex <> -1 _
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
             Then  
             Dim cls<OwnerU>_<TableU> As New sr<OwnerU>_<TableU>.<OwnerU>_<TableU>Class
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsNumericUpDown>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMaskedTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMultilineTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsRichTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsComboBox (Db)>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue)
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsNumericUpDown>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMaskedTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMultilineTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsRichTextBox>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text)
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsComboBox (Db)>
             cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue)
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
             cls<OwnerU>_<TableU> = cls<OwnerU>_<TableU>Data.Select_Record(cls<OwnerU>_<TableU>)
             If Not cls<OwnerU>_<TableU> Is Nothing Then
                  ec.ShowMessage(" Record already exists. ",  " <Head> ")
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsNumericUpDown>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMaskedTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMultilineTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsRichTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsComboBox (Db)>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsNumericUpDown>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMaskedTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMultilineTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsRichTextBox>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsComboBox (Db)>
                  txtNew<FieldU>.Focus()
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
                  Return False
             End If
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
        End If
           <ExitLoop>
        </If Loop>
---------------------------------------<Comment>
        Return True
    End Function

    Private Function GetSortDirection(ByVal column As String) As String
        Dim sortDirection = "ASC"
        Dim sortExpression = TryCast(ViewState("SortExpression"), String)
        If sortExpression IsNot Nothing Then
            If sortExpression = column Then
                Dim lastDirection = TryCast(ViewState("SortDirection"), String)
                If lastDirection IsNot Nothing _
                  AndAlso lastDirection = "ASC" Then
                    sortDirection = "DESC"
                End If
            End If
        End If
        ViewState("SortDirection") = sortDirection
        ViewState("SortExpression") = column
        Return sortDirection
    End Function

    Private Sub butRecords_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butRecords.Click
        grd<TableU>.PageIndex = 0
        grd<TableU>.PageSize = System.Convert.ToInt32(cmbRecords.Text)
        LoadGrid<OwnerU>_<TableU>()
    End Sub

    Private Sub butShowAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butShowAll.Click
        txtSearch.Text = Nothing
        Session.Remove("dv<OwnerU>_<TableU>")
        LoadGrid<OwnerU>_<TableU>()
    End Sub

    Private Sub butSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butSearch.Click
        Try
            Session.Remove("dv<OwnerU>_<TableU>")
            If Not IsNothing(Session("dv<OwnerU>_<TableU>")) Then
                dv<OwnerU>_<TableU> = CType(Session("dv<OwnerU>_<TableU>"), DataView)
            Else ' DataView was not found in the Session.
                dv<OwnerU>_<TableU> = cls<OwnerU>_<TableU>Data.Search(cmbFields.Text, cmbCondition.Text, txtSearch.Text).Tables(0).DefaultView
            	Session("dv<OwnerU>_<TableU>") = dv<OwnerU>_<TableU>
            End If
            If dv<OwnerU>_<TableU>.Count > 0 Then
                With grd<TableU>
                    .DataSource = dv<OwnerU>_<TableU>
                    .DataBind()
                End With
            End If
            If dv<OwnerU>_<TableU>.Count = 0 Then
                Dim dt As New DataTable()
                dt.Rows.Add(dt.NewRow())
            <If Loop>
                <IsComboBox (Db)>
                dt.Columns.Add("<RDisplayFieldU>", Type.GetType("System.<VBType>"))
                <IsNotComboBox (Db)>
                dt.Columns.Add("<FieldU>", Type.GetType("System.<VBType>"))
            </If Loop>
                dv<OwnerU>_<TableU> = dt.DefaultView
                Session("dv<OwnerU>_<TableU>") = dv<OwnerU>_<TableU>

                With grd<TableU>
                    .DataSource = dv<OwnerU>_<TableU>
                    .DataBind()
                End With

                Dim TotalColumns As Integer = grd<TableU>.Rows(0).Cells.Count
                grd<TableU>.Rows(0).Cells.Clear()
                grd<TableU>.Rows(0).Cells.Add(New TableCell())
                grd<TableU>.Rows(0).Cells(0).ColumnSpan = TotalColumns
                grd<TableU>.Rows(0).Cells(0).Text = "No Record Found"
            End If
            dv<OwnerU>_<TableU>.Sort = htmlHiddenSortExpression.Value
        Catch ex As Exception
	    ec.ShowMessage(ex.Message, " <Head> ")
        End Try
    End Sub

    Public Sub btnExport_Click(sender As System.Object, e As System.EventArgs) Handles btnExport.Click
        Try
            If ddlFile.SelectedValue = ".pdf" Then
                Dim dt As New DataTable()
                If Not String.IsNullOrEmpty(txtSearch.Text) Then
                    dt = cls<OwnerU>_<TableU>Data.Search(cmbFields.Text, cmbCondition.Text, txtSearch.Text).Tables(0)
                Else
                    dt = cls<OwnerU>_<TableU>Data.SelectAll().Tables(0)
                End If

                Dim pdfForm As New PDFform(dt, "<Head>", "Many")
                Dim document As Document = pdfForm.CreateDocument()
                Dim renderer As New PdfDocumentRenderer(True)
                renderer.Document = document
                renderer.RenderDocument()

                Dim stream As New MemoryStream()
                renderer.PdfDocument.Save(stream, False)

                Response.Clear()
                Response.ContentType = "application/" + ddlFile.SelectedItem.Text + ddlFile.SelectedValue
                Response.AddHeader("content-disposition", "attachment;filename=" + "Report" + ddlFile.SelectedValue)
                Response.BinaryWrite(stream.ToArray())
                Response.Flush()
                Response.[End]()
            Else
                Response.Clear()
                Response.Charset = ""
                Response.ContentEncoding = System.Text.Encoding.UTF8
                Response.Cache.SetCacheability(HttpCacheability.NoCache)
                Response.ContentType = "application/" + ddlFile.SelectedItem.Text + ddlFile.SelectedValue
                Response.AddHeader("content-disposition", "attachment;filename=" + "Report" + ddlFile.SelectedValue)

                Dim sw As New System.IO.StringWriter()
                Dim htw As New HtmlTextWriter(sw)
                Dim GVExport As New GridView()
                GVExport.DataSource = Session("dv<OwnerU>_<TableU>")
                GVExport.DataBind()
                GVExport.RenderControl(htw)

                Response.Write(sw)
                sw = Nothing
                htw = Nothing
                Response.Flush()
                Response.[End]()
            End If
        Catch
        End Try
    End Sub

End Class

